package com.dc.base.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;

import java.io.File;

public class GlideUtil {

    public static void loadImage(Context context, String url, ImageView imageView) {
        Glide.with(context).load(url).into(imageView);
    }

    public static void loadImage(Context context, String url, ImageView imageView, int defaultResId) {
        Glide.with(context).load(url).placeholder(defaultResId).error(defaultResId).into(imageView);
    }

    public static void loadImage(Context context, File file, ImageView imageView) {
        Glide.with(context).load(file).into(imageView);
    }

    public static void loadCircleImage(Context context, String url, ImageView imageView) {
        Glide.with(context).load(url).apply(RequestOptions.circleCropTransform()).into(imageView);
    }

    public static void loadCircleImage(Context context, File file, ImageView imageView) {
        Glide.with(context).load(file).apply(RequestOptions.circleCropTransform()).into(imageView);
    }

    /**
     * 加载圆角图片
     */
    public static void loadRoundedCornersImage(Context context, String url, ImageView imageView, float dp) {
        Glide.with(context).load(url).apply(RequestOptions.bitmapTransform(new RoundedCorners(DisplayUtil.dip2px(context, dp)))).into(imageView);
    }

    /**
     * 加载圆角图片
     */
    public static void loadRoundedCornersImage(Context context, File file, ImageView imageView, float dp) {
        Glide.with(context).load(file).apply(RequestOptions.bitmapTransform(new RoundedCorners(DisplayUtil.dip2px(context, dp)))).into(imageView);
    }

    /**
     * 设置动态GIF加载方式
     */
    public static void loadImageViewDynamicGif(Context context, String url, ImageView imageView) {
        Glide.with(context).asGif().load(url).into(imageView);
    }

    /**
     * 设置静态GIF加载方式
     */
    public static void loadImageViewStaticGif(Context context, String url, ImageView imageView) {
        Glide.with(context).asBitmap().load(url).into(imageView);
    }
}
